package com.huxin.servelt;

import com.alibaba.fastjson.JSON;
import com.huxin.pojo.BooksInfo;
import com.huxin.pojo.ConditionalQueryDTO;
import com.huxin.pojo.ProblemFeedback;
import com.huxin.pojo.UserInfo;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * 提交问题servlet
 */
@WebServlet("/submitProblem")
public class SubmitProblemServlet extends HttpServlet {
    private Userservice userservice = new Userservice();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String s = request.getReader().readLine();
        //todo
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        UserInfo userInfo = userservice.selectById(userId);
        ProblemFeedback problemFeedback = JSON.parseObject(s, ProblemFeedback.class);
        //设置用户名
        problemFeedback.setUsername(userInfo.getUsername());
        //设置提交时间
        problemFeedback.setSubmission_time(new Date(System.currentTimeMillis()));

        int i=userservice.submitProblem(problemFeedback);
        response.getWriter().write(String.valueOf(i));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
